package com.supermap.extend.trafficanalyst;

import com.alibaba.fastjson.JSONObject;
import com.supermap.data.*;

public class Test {

    public static void junctionQueryTest(){

        //参数1 点位
        GeoPoint geoPoint = new GeoPoint(114.4089678118,30.508106281);

        //参数2 半径范围 单位与路口数据集一致 通过 datasetVector.getPrjCoordSys().getCoordUnit() 查询
        //米转经纬度：米*0.00000898=度，近似值
        double distance = 0.00898;

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject resulut = trafficAnalyst.junctionQuery(geoPoint,distance);
        System.out.println("测试结果：" + resulut);

    }

    public static void linkQueryTest(){

        //参数1 点位
        GeoPoint geoPoint = new GeoPoint(114.40790936711623,30.50959965022656);

        //参数2 半径范围 单位与道路数据集一致 通过 datasetVector.getPrjCoordSys().getCoordUnit() 查询，
        //米转经纬度：米*0.00000898=度，近似值
        double distance = 0.00898;

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject resulut = trafficAnalyst.linkQuery(geoPoint,distance);
        System.out.println("测试结果：" + resulut);

    }

    public static void queryPreviousJunctionTest(){

        //参数1 路口id
        String junction_id = "wh_jn1";

        //参数2 路口进口方向
        String link_direction = "N";

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject result =  trafficAnalyst.queryPreviousJunction(junction_id,link_direction);
        System.out.println("result：" + result);
    }

    public static void findPathTest() {

        //参数1 点位
        Point2Ds point2Ds = new Point2Ds();
        point2Ds.add(new Point2D(114.4066401671865,30.509820905542036));
        point2Ds.add(new Point2D(114.407744,30.509161));
        point2Ds.add(new Point2D(114.406246,30.498155));

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject result =  trafficAnalyst.findPath(point2Ds);
        System.out.println("result:" + result);
    }

    public static void queryPreviousJunctionByGapTest(){

        //参数1 路口id
        String junction_id = "wh_jn1";

        //参数2 方向(上下游：downstream,upstream)
        String direction = "upstream";

        //参数3 间隔
        int gap = 6;

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject jsonObject =  trafficAnalyst.queryPreviousJunctionByGap(junction_id,direction,gap);
        System.out.println("结果："+jsonObject);
    }

    public static void queryJunctionByRegionBoundaryTest() {

        //参数1 面对象
        Point2Ds point2Ds = new Point2Ds();
        point2Ds.add(new Point2D(114.4078848043,30.5101347429));
        point2Ds.add(new Point2D(114.4082340033,30.5094423656));
        point2Ds.add(new Point2D(114.4073038094,30.5095868617));
        point2Ds.add(new Point2D(114.4078848043,30.5101347429));
        GeoRegion geoRegion = new GeoRegion(point2Ds);

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject result = trafficAnalyst.queryJunctionByRegionBoundary(geoRegion);
        System.out.println(result);
    }

    private static void findPathByNumTest() {

        //参数1 路口id集合
        String[] junction_ids = new String[]{"wh_jn1","wh_jn2"};

        //参数2 查询结果数量
        int num = 4;

        TrafficAnalyst trafficAnalyst = new TrafficAnalyst();
        JSONObject result =  trafficAnalyst.findPathByNum(junction_ids,num);
        System.out.println("result:" + result);
    }

    public static void main(String[] args) {

        String udbxFilePath = "Z:\\user\\盛视\\DRIS\\用户路网数据\\0918\\lwtest.udbx";
        TrafficAnalyst.initData(udbxFilePath);

//        junctionQueryTest();
//        linkQueryTest();
//        findPathTest();
//        queryPreviousJunctionTest();
//        queryPreviousJunctionByGapTest();
//        queryJunctionByRegionBoundaryTest();
        findPathByNumTest();
    }
}
